package com.zy.dubbo.demo.user.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zy.dubbo.demo.user.mapper.UserMapper;
import com.zy.dubbo.demo.user.model.User;
import com.zy.dubbo.demo.user.service.UserService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.util.List;

/**
 * UserServiceImpl
 *
 * @author Robbin Zhao
 * @since 2020-12-10
 */
@DubboService
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public User getUserById(Long id) {
        Assert.notNull(id,"userId is null");

        return userMapper.selectById(id);
    }

    @Override
    public List<User> getUserByName(String name) {
        Assert.hasLength(name,"name is empty");

        return userMapper.getByName(name);
    }

    @Override
    public Page<User> queryUserList(Page<User> page, String name) {
        Assert.notNull(page,"page is null");
        Assert.hasLength(name,"name is empty");

        List<User> users = userMapper.queryUserList(page, name);
        page.setRecords(users);
        return page;
    }
}
